//
//  AttendanceTableViewCell.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/12.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "AttendanceTableViewCell.h"

@implementation AttendanceTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        /**
         竖线
         */
        UIView *verLineView = [[UIView alloc] init];
        verLineView.backgroundColor = LineBackGroundColor;
        [self.contentView addSubview:verLineView];
        self.verLineView = verLineView;
        
        /**
         符号
         */
        UIImageView *bigImageView = [[UIImageView alloc] init];
        bigImageView.image = [UIImage imageNamed:@"icon_pointime"];
        [self.contentView addSubview:bigImageView];
        self.bigImageView = bigImageView;
        
        /**
         日Label
         */
        UILabel *dayLabel = [[UILabel alloc] init];
        dayLabel.textColor = CSColorFromRGB(0x666666);
        dayLabel.font = [UIFont systemFontOfSize:30];
        dayLabel.text = @"19";
        [self.contentView addSubview:dayLabel];
        self.dayLabel = dayLabel;
        
        /**
         月Label
         */
        UILabel *monthLabel = [[UILabel alloc] init];
        monthLabel.font = MidBigFont;
        monthLabel.text = @"11月";
        monthLabel.textColor = CSColorFromRGB(0x999999);
        [self.contentView addSubview:monthLabel];
        self.monthLabel = monthLabel;
        
        /**
         标题
         */
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"暗暗-游泳";
        titleLabel.font = [UIFont systemFontOfSize:21];
        titleLabel.textColor = CSColorFromRGB(0x333333);
        [self.contentView addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        
        /**
         详情
         */
        UILabel *detailLabel = [[UILabel alloc] init];
        detailLabel.text = @"19:00-20:00 李磊";
        detailLabel.font = MidBigFont;
        detailLabel.textColor = CSColorFromRGB(0x999999);
        [self.contentView addSubview:detailLabel];
        self.detailLabel = detailLabel;
        
        /**
         横线
         */
        UIView *horLineView = [[UIView alloc] init];
        horLineView.backgroundColor = LineBackGroundColor;
        [self.contentView addSubview:horLineView];
        self.horLineView = horLineView;
        
        [self setConstraints];

    }
    
    return self;
}


-(void)setConstraints{
    
    [self.verLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.contentView);
        
        make.left.mas_equalTo(self.contentView).offset(30);
        
        make.width.mas_equalTo(1);
        
        make.height.mas_equalTo(self.contentView);
    }];
    
    [self.bigImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.mas_equalTo(self.verLineView);
        
        make.centerY.mas_equalTo(self.titleLabel);
    }];
    
    [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.verLineView.mas_right);
        
        make.bottom.right.mas_equalTo(self.contentView);
        
        make.height.mas_equalTo(1);
    }];
    
    
    /**
     月
     */
    [self.monthLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.verLineView.mas_right).offset(25);
        
        make.top.mas_equalTo(self.contentView.mas_centerY).offset(5);
    }];
    
    /**
     日
     */
    [self.dayLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
    
        make.left.mas_equalTo(self.monthLabel);
        
        make.bottom.mas_equalTo(self.contentView.mas_centerY).offset(-5);
    }];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.dayLabel.mas_right).offset(22);
        
        make.centerY.mas_equalTo(self.dayLabel);
    }];
    
    [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.titleLabel);
        
        make.centerY.mas_equalTo(self.monthLabel);
    }];
    
}

-(void)setBrforeTiem:(NSString *)beforeTime andStartTime:(NSString *)startTime andEndTime:(NSString *)endTime{
    
    
    //中间的
    if ([startTime isEqualToString:beforeTime] && [startTime isEqualToString:endTime]) {
        
        self.bigImageView.hidden = YES;
        
        self.monthLabel.hidden = YES;
        
        self.dayLabel.hidden = YES;
        
        [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.titleLabel);
            
            make.bottom.right.mas_equalTo(self.contentView);
            
            make.height.mas_equalTo(1);
        }];
    }
    
    //最后一个
    if ([startTime isEqualToString:beforeTime] && ![startTime isEqualToString:endTime]) {
        
        self.bigImageView.hidden = YES;
        
        self.monthLabel.hidden = YES;
        
        self.dayLabel.hidden = YES;
        
        [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.verLineView.mas_right);
            
            make.bottom.right.mas_equalTo(self.contentView);
            
            make.height.mas_equalTo(1);
        }];
    }
    
    //第一个
    if (![startTime isEqualToString:beforeTime] && [startTime isEqualToString:endTime]) {
     
        self.bigImageView.hidden = NO;
        
        self.monthLabel.hidden = NO;
        
        self.dayLabel.hidden = NO;
        
        [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.titleLabel);
            
            make.bottom.right.mas_equalTo(self.contentView);
            
            make.height.mas_equalTo(1);
        }];
    }
    
    if (![startTime isEqualToString:beforeTime] && ![startTime isEqualToString:endTime]) {
        
        self.bigImageView.hidden = NO;
        
        self.monthLabel.hidden = NO;
        
        self.dayLabel.hidden = NO;
        
        [self.horLineView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.left.mas_equalTo(self.verLineView);
            
            make.bottom.right.mas_equalTo(self.contentView);
            
            make.height.mas_equalTo(1);
        }];
    }
}
@end
